import pymysql
import time

#测试数据库语句

conn = pymysql.connect(host='192.168.187.130',user='root',passwd='123456',db='homework')
cur = conn.cursor()
mask = 9999
name = "测试语句3"

#cur.execute("insert into project(mask,name,date,time,uprize,downprize,midprize,bigtype,smalltype,averageprofit) values(9999,'测试语句','2021-2-13',40,5000,3000,4000,null,null,100);")
#cur.execute("insert into project(mask,name) values(9999,'测试语句');")
#sql = """select * from project;"""
#cur.execute(sql)
sql = """ insert into project(mask,name,date,time,uprize,downprize,midprize,bigtype,smalltype,averageprofit) values(6666,'测试语句','2021-2-13',40,5000,3000,4000,null,null,100)"""
'''
sql = "INSERT INTO EMPLOYEE(FIRST_NAME, \
       LAST_NAME, AGE, SEX, INCOME) \
       VALUES (%s, %s, %s, %s, %s )" % \
       ('Mac', 'Mohan', 20, 'M', 2000)
sql = "INSERT INTO project(MASK, NAME) \
       VALUES (%d, %s)" % \
       (9999, '测试语句3')
cur.execute(sql)
'''

'''
print(str(cur.execute(sql)))
print(str(conn.commit()))

results = cur.fetchone()
#for row in results:
#print(str(row))

print(results)
cur.close()
conn.close()
'''

try:
    cur.execute(sql)
    conn.commit()
except:
    sql = """update project set name = '测试语句3' , date = '2021-2-16' , time = 50 , uprize = 2500, downprize = 5000 , midprize = 3750 , averageprofit = 75 where mask=6666 """
    cur.execute(sql)
    conn.commit()
else:
    cur.close()
    conn.close()
